package com.cnpc.ds.utils;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

public class SqlUtil {

    /**
     * 允许前段传参的排序字段 针对于pc后端
     */
    private final static String[] SORT_FIELD = {"MATERIAL_NAME","SPUDIN_NO","ORDER_SORT","SORT_ORDER","MEASURED_DEPTH","DEPTH","CODE","CREATE_DATE","BOTTOM_MD", "UPDATE_DATE","WELL_MD","SAMPLE_MD","LITHOLOGY_TOP","FORMATIONTEST_MD","TEST_MD",
            "BREAKDOWN_MD","HOLE_MD","COMPLEX_MD","FORMATION_TEST_MD","FORMATION_TOP","WELL_DEPTH","TEMPLATE_NAME","GROUP_NAME"};

    /**
     * 排序字段检查 防止sql注入
     */
    public static Boolean sortFieldCheck(String sort) {
        if(ArrayUtil.contains(SORT_FIELD, sort.toUpperCase())){
            return true;
        }
        sort=StrUtil.toSymbolCase(sort, StrUtil.C_UNDERLINE).toUpperCase();
        return ArrayUtil.contains(SORT_FIELD, sort);
    }

    /**
     * 过滤 -9999的数据
     * @return
     */
    public static void filtrationData(String str, QueryWrapper qw) {
        String[] split = str.split(",");
        for (String s : split) {
            qw.ne(s,"-9999");
        }
    }
}
